home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SVEditGXPrinting.c
-
- Contains: Adds GX printing functionality to 7Edit
-
- Written by: Original version by Jon Lansdell and Nigel Humphreys.
- 3.1 updates by Greg Sutton.
-
- Copyright: Copyright ©1995-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/19/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- #include <Gestalt.h>
- #include "SVEditPrinting.h"
- #include "SVEditWindow.h"
- #include "SVEditGlobals.h"
- #include "SVEditMain.h"
-
- // Constants
-
- #define kGraphicsHeapSize ((long) 300 * 1024)
-
- // Globals
-
-
-
-
- //-------------------------------------------------------
- // GetRectOfPage
- //
- // This returns a QuickDraw rect for the current printer page.
- // If gx is not present if uses rPage from the document's THPrint.
- // If gx is present then we get a GXRectangle from the requested
- // page's format. It then converts this to a Rect. This could be
- // extended to handle custom formated pages.
- //-------------------------------------------------------
-
- #pragma segment Main
-
- void GetRectOfPage( DPtr theDoc,
- Rect *pageRect )
- {
-
- *pageRect = (*(theDoc->thePrintSetup))->prInfo.rPage;
- OffsetRect( pageRect, -pageRect->left, -pageRect->top);
- }
-
-
-
-
-
- //-------------------------------------------------------
- // DuplicateStyleTERec
- //
- // This copies the styled TERec in theDoc. It puts it into
- // the destPort
- //-------------------------------------------------------
-
- #pragma segment Main
-
- void DuplicateStyleTERec( TEHandle hSourceTE,
- TEHandle *hDestTE,
- Rect *destRect,
- GrafPtr destPort )
- {
- GrafPtr oldPort;
- short oldSelStart;
- short oldSelEnd;
- StScrpHandle printerTextStyles;
-
- // Set up the ports
- GetPort(&oldPort);
- SetPort(destPort);
-
- // Create a temporary Text Edit and copy the windows text edit into it
- *hDestTE = TEStyleNew(destRect, destRect);
-
- // Select all the text (preserving the previous settings) so that we can use
- // GetTylScrap (or TEGetStyleScrapHandle ) to get the style of the whole TERec
- oldSelStart = (*hSourceTE)->selStart;
- oldSelEnd = (*hSourceTE)->selEnd;
- TESetSelect(0,(*hSourceTE)->teLength, hSourceTE);
-
- // Get the style
- printerTextStyles = TEGetStyleScrapHandle(hSourceTE);
-
- // Revert the selection range
- TESetSelect(oldSelStart, oldSelEnd, hSourceTE);
-
- // Move the text from the documents TERec and add the style (got above) to it
- HLock((Handle)((*hSourceTE)->hText));
- TEStyleInsert ( (Ptr)*((*hSourceTE)->hText),
- (*hSourceTE)->teLength,
- printerTextStyles,
- *hDestTE);
- HUnlock((Handle)((*hSourceTE)->hText));
-
- // Deactivat the temporary TERec
- TEDeactivate(*hDestTE);
-
- // Reset the port
- SetPort(oldPort);
- }
-
-